package com.zy.pro.order.web;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zy.core.model.PageView;
import com.zy.core.web.BaseController;
import com.zy.pro.order.model.Comment;
import com.zy.pro.order.service.CommentService;
import com.zy.pro.order.web.form.CommentSearchForm;
/**
 * 评论管理控制器
 *
 */
@Controller
@RequestMapping("/control/order/commentController")
public class CommentController extends BaseController {

	private static final Logger logger = Logger.getLogger(CommentController.class);
	
	/**
	 * 评论管理服务类
	 */
	@Resource(name = "commentServiceImpl")
	private CommentService commentService;
	
	/**
	 * 列出评论管理
	 */
	@RequestMapping("/list")
	public String list(CommentSearchForm form, ModelMap map) {
		try {
			//设置查询排序
			//TODO eg:form.getOrderby().put("id", "asc");
			
			
			//创建页面对象
			PageView<Comment> pageView = new PageView<Comment>(12, form.getPage());
			form.setFirstResult(pageView.getFirstResult());
			form.setMaxResult(pageView.getMaxresult());
			pageView.setQueryResult(commentService.getData(form));
			map.addAttribute("pageView", pageView);
			map.addAttribute("form", form);
			//TODO 转发页面
			return "";
		} catch(Exception e){
			logger.error(e);
			return "error";
		}
	}
	
	/**
	 * 显示添加评论管理
	 */
	@RequestMapping("/displayAdd")
	public String displayAdd(Comment comment, ModelMap map) {
		try {
			//TODO 加载显示页面数据
			
			
			//TODO 转发页面
			return "";
		} catch(Exception e){
			logger.error(e);
			return "error";
		}
	}
	
	/**
	 * 添加评论管理
	 */
	@RequestMapping("/add")
	public String add(Comment comment, ModelMap map) {
		try {
			//TODO 设置comment  eg:主键信息
			
			commentService.save(comment);
			return list(new CommentSearchForm(), map);
		} catch(Exception e){
			logger.error(e);
			return "error";
		}
	}
	
	/**
	 * 显示编辑评论管理
	 */
	@RequestMapping("/displayEdit")
	public String displayEdit(CommentSearchForm form, ModelMap map) {
		try {
			//TODO 查询对象
			//eg:Comment comment = commentService.find(form.getId());
			//eg:map.addAttribute("entity", comment);
			
			
			//TODO 转发页面
			return "";
		} catch (Exception e) {
			logger.error(e);
			return "error";
		}
	}
	
	/**
	 * 编辑评论管理
	 */
	@RequestMapping("/edit")
	public String edit(Comment Comment, ModelMap map) {
		try {
			//TODO:处理评论管理
			
			
			commentService.updateBySelective(Comment);
			return list(new CommentSearchForm(), map);
		} catch (Exception e) {
			logger.error(e);
			return "error";
		}
		
	}

	/**
	 * 删除单个评论管理
	 */
	@RequestMapping("/deletecomment")
	public String delete(CommentSearchForm form, ModelMap map) {
		try {
			//TODO  eg:commentService.delete(form.getId());
			
			return list(form, map);
		} catch (Exception e) {
			logger.error(e);
			return "error";
		}
	}
	
	/**
	 * 批量删除评论管理
	 */
	@RequestMapping("/batchDelete")
	public String deletes(CommentSearchForm form, ModelMap map) {
		try {
//			TODO  eg:commentService.batchDelete(form.getIds());
			
			return list(form, map);
		} catch (Exception e) {
			logger.error(e);
			return "error";
		}
	}
}
